package my.jwds.p479;

public class LargestPalindrome {
    public static void main(String[] args) {
        Solution obj = new Solution();
        System.out.println(obj.largestPalindrome(2));
    }

    static class Solution {
        public int largestPalindrome(int n) {
            if(n ==1)return 9;
            int num1 = (int) Math.pow(10,n)-1;
            for (int i = num1; i > 0; i--) {
                long c = i;
                for (int j = 1; j <= i; j*=10) {
                    c = c*10 + i/j%10;
                }

                for (long j = num1; j*j>=c; j--) {
                    if (c % j == 0)return (int) (c %1337);
                }
            }
            return -1;
        }
    }
}